﻿using System;
using System.Collections.Generic;

using System.Text;
using SH;

namespace MTS
{
   public class MessTransceiver
    {
        static bool bInit = false;
        static mtVHostManager m_manager = new mtVHostManager();

        public static ImtSysManage mtGet(mtRegisterInfo info)
        {
            if(bInit == false)
            {
               m_manager.Initialize();
            
            }

            var host = m_manager.CreateVHost(info);

            if (host == null)
                return null;
            else
            {
                var pInterface = host.QueryInterface("mtSysManage");

                if (pInterface != null)
                    return (mtSysManage)pInterface;
                else
                    return null;
            }

        }

        public static ImtSysManagerServer mtGetServer(mtRegisterInfo info)
        {
            if (bInit == false)
            {
               m_manager.Initialize();

            }

            var host = m_manager.CreateVHost(info);

            if (host == null)
                return null;
            else
            {
                var pInterface = host.QueryInterface("mtSysManageServer");

                if (pInterface != null)
                    return (mtSysManageServer)pInterface;
                else
                    return null;

            }
        }

        public static void mtRelease(ImtSysManage client)
        {
            mtSysManage  sysManage = (mtSysManage)client;

            var host = sysManage.GetVHost();

            if (host == null)
                return;

            m_manager.DestroyVHost(host);
        }

        public static void mtReleaseServer(ImtSysManagerServer server)
        {
            mtSysManageServer sysManageServer = (mtSysManageServer)server;

            var host = sysManageServer.GetVHost();

            if (host == null)
                return;

            m_manager.DestroyVHost(host);

        }


    }
}